//
//  CollectViewController.m
//  LOL_PalmarHelper
//
//  Created by dlios on 15-7-6.
//  Copyright (c) 2015年 hantao. All rights reserved.
//

#import "CollectViewController.h"

@interface CollectViewController ()

@end

@implementation CollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.navigationItem.title = @"我的收藏";
    
    self.tableV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, self.view.frame.size.height-64-49) style:UITableViewStylePlain];
    
    self.tableV.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.tableV];

    self.tableV.delegate = self;
    self.tableV.dataSource = self;
    
 
    [[collect shareData] openColl];
    [[collect  shareData]createTable];
    
    
    
    NSMutableArray *array = [[collect shareData]selectAll];
    if (array.count == 0) {
        
        UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"" message:@"亲,收藏空空如也哦" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [self.view addSubview:al];
        [al show];
        [al release];
    }
    
    NSLog(@"---%ld",array.count);
    
    
    
    [self.tableV setEditing:NO animated:YES];
    
    self.array = [NSMutableArray array];
    
    
    
    
    
    
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
 HeroDetailViewController *viewVC = [[HeroDetailViewController alloc] init];
    
    [[collect shareData ]openColl];
    NSMutableArray *array =[[collect shareData] selectAll];
    
    HeroDetailModel *hero = [[HeroDetailModel alloc] init];
    
    hero = [array objectAtIndex:indexPath.row];
    
    viewVC.enName =hero.name;

    [self.navigationController pushViewController:viewVC animated:YES];
    
    
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
   return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSMutableArray *array = [[collect shareData] selectAll];
    return array.count;
   
    
}



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifer = @"cell";
    collectTableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer ];
    
    if (cell == nil) {
        
      cell  = [[collectTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
       
    
    }
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    NSMutableArray *array = [[collect shareData]selectAll];
    
    HeroDetailModel *hero = [[HeroDetailModel alloc] init];
    hero = [array objectAtIndex:indexPath.row];
    cell.textLabel.text = hero.displayName;

    return cell;
    
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return UITableViewCellEditingStyleDelete;
}



-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    return @"删除";
}



-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        NSMutableArray *array = [[collect shareData] selectAll];
        
        HeroDetailModel *model = [array objectAtIndex:indexPath.row];
        
        [array removeObjectAtIndex:indexPath.row];
        
        [[collect shareData]deletheroName:model.name];
        
        [tableView reloadData];
        
    }
    
    
}







-(void)setEditing:(BOOL)editing animated:(BOOL)animated//出去编辑状态
{
    
    [super setEditing:editing animated:animated];
    [self.tableV setEditing:editing animated:animated];
    
}




     











- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
